package com.jacklei;

import com.jacklei.util.ArrUtil;
import com.sun.org.apache.bcel.internal.generic.BREAKPOINT;

import java.util.Arrays;

//冒泡排序
public class BubbleSort {
    public static void main(String[] args) {
        int[] arr = ArrUtil.getRandomArr();
        int[] arr1 = arr;
        int[] arr2 = ArrUtil.copyArr(arr);

        Arrays.sort(arr1);
        sort(arr2);

        for (int i = 0; i < arr.length; i++) {
            if(arr1[i] != arr2[i]) {
                System.out.println("fail！！！！ i:" + "i => arr1:" + arr1[i] + " =>arr2:" + arr2[i]);
                break;
            }
            if (i == arr.length-1) System.out.println("successful");
        }
        ArrUtil.seeArr(arr1,arr2);
    }

    public static void sort(int[] arr){
        for (int i = 0; i < arr.length; i++) {
            for (int j = 0; j < arr.length-1-i; j++) {
                if(arr[j] > arr[j+1]){
                    ArrUtil.swap(arr, j ,j+1);
                }
            }
        }
    }

}
